
package com.creating.mict.action;



import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.creating.mict.common.Dom4j;
import com.creating.mict.common.mess.SMSCaClient;
import com.creating.mict.domain.Patient;
import com.creating.mict.domain.PatientRule;
import com.creating.mict.domain.PatientSetting;
import com.creating.mict.domain.XyjRecord;
import com.creating.mict.service.IPatientService;
import com.creating.mict.service.IXyjService;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 
* @ClassName: XyjAction 
* @Description: 血压计模块ACtion
* @author xuelei
* @date Dec 27, 2012 10:28:55 AM 
*
 */
@SuppressWarnings("serial")
public class XyjAction extends ActionSupport {

	@Resource
	private IXyjService xyjService;
	@Resource
	private IPatientService patientService;
	
	/**
	 * 
	* @Title: queryXyjRecord 
	* @Description: 获取血压计测量值
	* @param @return 
	* @return String    返回类型 
	* @throws
	 */
	public String queryXyjRecord() {
		HttpServletRequest request = ServletActionContext.getRequest();
		
		String loginName = (String)request.getSession().getAttribute("loginName");
		String loginOffice = (String)request.getSession().getAttribute("loginOffice");
		String loginType = (String)request.getSession().getAttribute("loginType");
		
		if(loginType.equals("1")) {
			
		} else {
			foffice = loginOffice;
		}
		
		if(fetime == null || fetime.equals("")) {
			
		}
		List<XyjRecord> list = xyjService.queryPatientXyj(loginName, foffice, fbtime, fetime, fstate, fkeywords, ftakeBack);
		
		if (list == null) {
			total = 0;
		} else {
			total = list.size();
		}
		
		StringBuffer jsonStr = new StringBuffer("[");
		if (start + limit > total)
			limit = total - start;
		for (int i = start; i < start + limit; i++)
		{
			XyjRecord xr = new XyjRecord();
			xr = list.get(i);
			jsonStr.append("{");
			jsonStr.append("fpid:'").append(xr.getFpid()).append("',");
			jsonStr.append("fname:'").append(xr.getFname()).append("',");
			jsonStr.append("fsex:'").append(xr.getFsex()).append("',");
			jsonStr.append("fstate:'").append(xr.getFstate()).append("',");
			jsonStr.append("fphone1:'").append(xr.getFphone()).append("',");
			jsonStr.append("fssy:'").append(xr.getFssy()).append("',");
			jsonStr.append("fszy:'").append(xr.getFszy()).append("',");
			jsonStr.append("fxl:'").append(xr.getFxl()).append("',");
			jsonStr.append("fstate_data:'").append(xr.getFstate_data()).append("',");
			jsonStr.append("fdate:'").append(xr.getFdateStr()).append("',");
			jsonStr.append("frdate:'").append(xr.getFrdateStr()).append("'");
			
			if (i == (start + limit) - 1)
				jsonStr.append("}");
			else
				jsonStr.append("},");
		}
		jsonStr.append("]");
		String str = "{totalProperty: " + list.size() + ", root:" + jsonStr + "}";
		request.setAttribute("result", str);
		return "success";
	}
	
	
	
	/**
	 * 
	* @Title: produceXyjToChart 
	* @Description: 获取血压及心率测量数据变化曲线
	* @param @return 
	* @return String    返回类型 
	* @throws
	 */
	public String produceXyjToChart() {
		HttpServletRequest request = ServletActionContext.getRequest();
		String str = xyjService.produceXyjToChart(fbtime, fetime, fphone1, fname);
		request.setAttribute("result", str);
		return "success";
	}
	
	
	/**
	 * 
	* @Title: produceXyjToChartClient 
	* @Description: 获取血压计测量数据变化曲线_客户端
	* @param @return 
	* @return String    返回类型 
	* @throws
	 */
	public String produceXyjToChartClient() {
		HttpServletRequest request = ServletActionContext.getRequest();
		
		Patient patient = patientService.queryPatientByKeyWords(fpid);
		String str = xyjService.produceXyjToChart(fbtime, fetime, patient.getFphone1(), patient.getFname());
		
		request.getSession().setAttribute("foffice", patient.getFoffice());
		request.setAttribute("result", str);
		return "success";
	}
	
	
	/**
	 * 
	* @Title: produceXyjToChartByPerson 
	* @Description: 外网查询获取血压及心率测量数据变化曲线
	* @param @return 
	* @return String    返回类型 
	* @throws
	 */
	public String produceXyjToChartByPerson() {
		HttpServletRequest request = ServletActionContext.getRequest();
		String certCode = (String)request.getSession().getAttribute("certCode");
		
		String str = "";
		if(fstate == null || fstate.equals("")) {
			fstate = "30";
		}
		if(certCode != null && certCode.equals(fkeywords)) {
			str = xyjService.produceXyjToChartByPerson(fphone1, fstate);
		}
		
		request.setAttribute("result", str);
		return "success";
	}
	
	/**
	 * 
	* @Title: refreshXyjInfo 
	* @Description: 手动获取监测信息 
	* @param @return 
	* @return String    返回类型 
	* @throws
	 */
	public String refreshXyjInfo() {
		HttpServletRequest request = ServletActionContext.getRequest();
		SMSCaClient smscall = new SMSCaClient();
		Dom4j.readXyjReceiveMessXmlAndSave(smscall.testPost(smscall.receiveMessXmlInfo()));
		
		request.setAttribute("result", "OK");
		return "success";
	}
	
	/**
	 * 
	* @Title: saveXyjOfSetting 
	* @Description: 保存血压设定的临界值 
	* @param @return 
	* @return String    返回类型 
	* @throws
	 */
	public String saveXyjOfSetting() {
		HttpServletRequest request = ServletActionContext.getRequest();
		PatientSetting ps = patientService.getPatientSettingInfoByPhone(fphone1);
		if(ps == null) {
			ps = new PatientSetting();
		}
		ps.setFphone(fphone1);
		ps.setFssy_high(fssy_high);
		ps.setFssy_low(fssy_low);
		ps.setFszy_high(fszy_high);
		ps.setFszy_low(fszy_low);
		ps.setFxl_high(fxl_high);
		ps.setFxl_low(fxl_low);
		ps.setFmyc_high(fmyc_high);
		ps.setFmyc_low(fmyc_low);
		
		patientService.savePatientSetting(ps);
//		xyjService.saveXyjOfSetting(fphone1, fssy_low, fssy_high, fszy_low, fszy_high, fxl_low, fxl_high, fmyc_low, fmyc_high);
		// fcqxt_low, fcqxt_high, fchxt1_low, fchxt1_high, fchxt2_low, fchxt2_high);
		request.setAttribute("result", "OK");
		return "success";
	}
	
	
	/**
	 * 
	* @Title: getPatientSettingInfoByPhone 
	* @Description: 获取患者设置信息 
	* @param @param fphone
	* @param @return 
	* @return PatientSetting    返回类型 
	* @throws
	 */
	public String getPatientSettingInfoByPhone() {
		HttpServletRequest request = ServletActionContext.getRequest();
		PatientSetting ps = new PatientSetting();
		if(fphone1 == null || fphone1.equals("")) {
			fphone1 = "10000000"; //空号
		}
		ps = xyjService.getPatientSettingInfoByPhone(fphone1);
		String strTemp = "";
//		strTemp = ps.getFssy_low() + ", "
//		        + ps.getFssy_high() + ", "
//		        + ps.getFszy_low() + ", "
//		        + ps.getFszy_high() + ", "
//		        + ps.getFxl_low() + ", "
//		        + ps.getFxl_high() + ", "
//		        + ps.getFmyc_low() + ", "
//		        + ps.getFmyc_high() + ", "
//		        + ps.getFcqxt_low() + ", "
//		        + ps.getFcqxt_high() + ", "
//		        + ps.getFchxt1_low() + ", "
//		        + ps.getFchxt1_high() + ", "
//		        + ps.getFchxt2_low() + ", "
//		        + ps.getFchxt2_high() + " "
//		        ;
		
		strTemp = "{fssy_low:'" + ps.getFssy_low() + "', "
		        + "fssy_high:'" + ps.getFssy_high() + "', "
		        + "fszy_low:'" + ps.getFszy_low() + "', "
		        + "fszy_high:'" + ps.getFszy_high() + "', "
		        + "fxl_low:'" + ps.getFxl_low() + "', "
		        + "fxl_high:'" + ps.getFxl_high() + "', "
		        + "fmyc_low:'" + ps.getFmyc_low() + "', "
		        + "fmyc_high:'" + ps.getFmyc_high() + "', "
		        + "fcqxt_low:'" + ps.getFcqxt_low() + "', "
		        + "fcqxt_high:'" + ps.getFcqxt_high() + "', "
		        + "fchxt1_low:'" + ps.getFchxt1_low() + "', "
		        + "fchxt1_high:'" + ps.getFchxt1_high() + "', "
		        + "fchxt2_low:'" + ps.getFchxt2_low() + "', "
		        + "fchxt2_high:'" + ps.getFchxt2_high() + "' "
		        + "}";
		request.setAttribute("result", "{totalProperty: 1, root:[" + strTemp + "]}");
		return "success";
	}
	
	
	
	private int limit = 50; //分页结束
	private int start = 0;  //分页起始
	private int total;		//总页数
	
	private String foffice;
	
	private String query;
	private String fbtime;
	private String fetime;
	private String fstate;
	private String fkeywords;
	private String fvalueType;
	private String fvalue1;
	private String fvalue2;
	private String ftakeBack;
	private String fcontent;
	
	private String fpid;
	private String fname;
	private String fname_pym;
	private String fsex;
	private String fidcd;
	private String fadd_jd;
	private String fadd_jd_pym;
	private String fadd_detail;
	private String fpcs;
	private String fjwh;
	private String fjwh_pym;
	private String fphone1;
	private String fphone2;
	private String fsign_doctor;
	private String fsign_type;
	private Date fsign_date;
	private String fsign_state;
	private String fybkh;
	
	private String flis;
	private String fxyj;
	private String fyytx;
	
	//监测信息临界值
	private String fssy_low;
	private String fssy_high;
	private String fszy_low;
	private String fszy_high;
	private String fxl_low;
	private String fxl_high;
	private String fmyc_low;
	private String fmyc_high;
	private String fcqxt_low;
	private String fcqxt_high;
	private String fchxt1_low;
	private String fchxt1_high;
	private String fchxt2_low;
	private String fchxt2_high;
	
	
	
	private String fphone3;


	public String getFybkh() {
		return fybkh;
	}

	public void setFybkh(String fybkh) {
		this.fybkh = fybkh;
	}

	public String getFpid() {
		return fpid;
	}


	public void setFpid(String fpid) {
		this.fpid = fpid;
	}


	public String getFname_pym() {
		return fname_pym;
	}


	public void setFname_pym(String fname_pym) {
		this.fname_pym = fname_pym;
	}


	public String getFsex() {
		return fsex;
	}


	public void setFsex(String fsex) {
		this.fsex = fsex;
	}


	public String getFidcd() {
		return fidcd;
	}


	public void setFidcd(String fidcd) {
		this.fidcd = fidcd;
	}


	public String getFadd_jd() {
		return fadd_jd;
	}


	public void setFadd_jd(String fadd_jd) {
		this.fadd_jd = fadd_jd;
	}


	public String getFadd_jd_pym() {
		return fadd_jd_pym;
	}


	public void setFadd_jd_pym(String fadd_jd_pym) {
		this.fadd_jd_pym = fadd_jd_pym;
	}


	public String getFadd_detail() {
		return fadd_detail;
	}


	public void setFadd_detail(String fadd_detail) {
		this.fadd_detail = fadd_detail;
	}


	public String getFpcs() {
		return fpcs;
	}


	public void setFpcs(String fpcs) {
		this.fpcs = fpcs;
	}


	public String getFjwh() {
		return fjwh;
	}


	public void setFjwh(String fjwh) {
		this.fjwh = fjwh;
	}


	public String getFjwh_pym() {
		return fjwh_pym;
	}


	public void setFjwh_pym(String fjwh_pym) {
		this.fjwh_pym = fjwh_pym;
	}


	public String getFphone1() {
		return fphone1;
	}


	public void setFphone1(String fphone1) {
		this.fphone1 = fphone1;
	}


	public String getFphone2() {
		return fphone2;
	}


	public void setFphone2(String fphone2) {
		this.fphone2 = fphone2;
	}


	public String getFsign_doctor() {
		return fsign_doctor;
	}


	public void setFsign_doctor(String fsign_doctor) {
		this.fsign_doctor = fsign_doctor;
	}


	public String getFsign_type() {
		return fsign_type;
	}


	public void setFsign_type(String fsign_type) {
		this.fsign_type = fsign_type;
	}


	public Date getFsign_date() {
		return fsign_date;
	}


	public void setFsign_date(Date fsign_date) {
		this.fsign_date = fsign_date;
	}


	public String getFsign_state() {
		return fsign_state;
	}


	public void setFsign_state(String fsign_state) {
		this.fsign_state = fsign_state;
	}


	public int getLimit() {
		return limit;
	}


	public void setLimit(int limit) {
		this.limit = limit;
	}


	public int getStart() {
		return start;
	}


	public void setStart(int start) {
		this.start = start;
	}


	public int getTotal() {
		return total;
	}


	public void setTotal(int total) {
		this.total = total;
	}


	public String getFbtime() {
		return fbtime;
	}


	public void setFbtime(String fbtime) {
		this.fbtime = fbtime;
	}


	public String getFetime() {
		return fetime;
	}


	public void setFetime(String fetime) {
		this.fetime = fetime;
	}


	public String getFstate() {
		return fstate;
	}


	public void setFstate(String fstate) {
		this.fstate = fstate;
	}


	public String getFkeywords() {
		return fkeywords;
	}


	public void setFkeywords(String fkeywords) {
		this.fkeywords = fkeywords;
	}


	public String getFname() {
		return fname;
	}


	public void setFname(String fname) {
		this.fname = fname;
	}

	public String getFvalueType() {
		return fvalueType;
	}

	public void setFvalueType(String fvalueType) {
		this.fvalueType = fvalueType;
	}

	public String getFvalue1() {
		return fvalue1;
	}

	public void setFvalue1(String fvalue1) {
		this.fvalue1 = fvalue1;
	}

	public String getFvalue2() {
		return fvalue2;
	}

	public void setFvalue2(String fvalue2) {
		this.fvalue2 = fvalue2;
	}

	public String getFtakeBack() {
		return ftakeBack;
	}

	public void setFtakeBack(String ftakeBack) {
		this.ftakeBack = ftakeBack;
	}

	public String getQuery() {
		return query;
	}

	public void setQuery(String query) {
		this.query = query;
	}

	public String getFlis() {
		return flis;
	}

	public void setFlis(String flis) {
		this.flis = flis;
	}

	public String getFxyj() {
		return fxyj;
	}

	public void setFxyj(String fxyj) {
		this.fxyj = fxyj;
	}

	public String getFyytx() {
		return fyytx;
	}

	public void setFyytx(String fyytx) {
		this.fyytx = fyytx;
	}

	public String getFssy_low() {
		return fssy_low;
	}

	public void setFssy_low(String fssy_low) {
		this.fssy_low = fssy_low;
	}

	public String getFssy_high() {
		return fssy_high;
	}

	public void setFssy_high(String fssy_high) {
		this.fssy_high = fssy_high;
	}

	public String getFszy_low() {
		return fszy_low;
	}

	public void setFszy_low(String fszy_low) {
		this.fszy_low = fszy_low;
	}

	public String getFszy_high() {
		return fszy_high;
	}

	public void setFszy_high(String fszy_high) {
		this.fszy_high = fszy_high;
	}

	public String getFxl_low() {
		return fxl_low;
	}

	public void setFxl_low(String fxl_low) {
		this.fxl_low = fxl_low;
	}

	public String getFxl_high() {
		return fxl_high;
	}

	public void setFxl_high(String fxl_high) {
		this.fxl_high = fxl_high;
	}


	public String getFcontent() {
		return fcontent;
	}

	public void setFcontent(String fcontent) {
		this.fcontent = fcontent;
	}

	public String getFphone3() {
		return fphone3;
	}

	public void setFphone3(String fphone3) {
		this.fphone3 = fphone3;
	}

	public String getFmyc_low() {
		return fmyc_low;
	}

	public void setFmyc_low(String fmyc_low) {
		this.fmyc_low = fmyc_low;
	}

	public String getFmyc_high() {
		return fmyc_high;
	}

	public void setFmyc_high(String fmyc_high) {
		this.fmyc_high = fmyc_high;
	}

	public String getFcqxt_low() {
		return fcqxt_low;
	}

	public void setFcqxt_low(String fcqxt_low) {
		this.fcqxt_low = fcqxt_low;
	}

	public String getFcqxt_high() {
		return fcqxt_high;
	}

	public void setFcqxt_high(String fcqxt_high) {
		this.fcqxt_high = fcqxt_high;
	}

	public String getFchxt1_low() {
		return fchxt1_low;
	}

	public void setFchxt1_low(String fchxt1_low) {
		this.fchxt1_low = fchxt1_low;
	}

	public String getFchxt1_high() {
		return fchxt1_high;
	}

	public void setFchxt1_high(String fchxt1_high) {
		this.fchxt1_high = fchxt1_high;
	}

	public String getFchxt2_low() {
		return fchxt2_low;
	}

	public void setFchxt2_low(String fchxt2_low) {
		this.fchxt2_low = fchxt2_low;
	}

	public String getFchxt2_high() {
		return fchxt2_high;
	}

	public void setFchxt2_high(String fchxt2_high) {
		this.fchxt2_high = fchxt2_high;
	}

	public String getFoffice() {
		return foffice;
	}

	public void setFoffice(String foffice) {
		this.foffice = foffice;
	}


}
